package com.steven.ourcontest.information.widget

import android.app.Dialog
import android.content.Context
import android.view.Gravity
import android.view.ViewGroup
import com.steven.ourcontest.R
import com.steven.ourcontest.information.bean.UserDetail
import kotlinx.android.synthetic.main.dialog_confirm_cancel.*

class ConfirmCancelDialog(
    context: Context,
    themeId: Int = R.style.dialog
) :
    Dialog(context, themeId) {
    private var content: String = ""
    private var confirmClick: (() -> Unit)? = null

    init {
        setContentView(R.layout.dialog_confirm_cancel)
        setCancelable(true)
        window?.setGravity(Gravity.CENTER)
        window?.setLayout(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT
        )
    }

    fun setContent(content:String): ConfirmCancelDialog {
        this.content = content
        return this
    }

    fun setConfirmClick(confirmClick: (() -> Unit)): ConfirmCancelDialog {
        this.confirmClick = confirmClick
        return this
    }

    override fun show() {
        tv_dialog_content?.text = content
        tv_confirm?.setOnClickListener {
            confirmClick?.invoke()
        }
        tv_cancel.setOnClickListener {
            dismiss()
        }
        super.show()
    }
}